<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Dangle
 *
 * @author sunday add 2014.5.28  modify by dragon.hu @2016.2.24
 */
require_once 'BaseChannel.php';

//暴风
class Baofeng implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="jNft4CyZ@4AjYAc((QzQbpwhjJpQSA2T"; //秘钥
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey="jNft4CyZ@4AjYAc((QzQbpwhjJpQSA2T"; //秘钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("baofeng", $_REQUEST);
		
		$amount = $_REQUEST['amount'];  //金额(元)
		$bill_no = $_REQUEST['bill_no'];  //订单号
		$extra = $_REQUEST['extra'];  //扩展
		$game_id = $_REQUEST['game_id'];  //游戏id
		$server_id = $_REQUEST['server_id'];  //服务器编号
		$user_id = $_REQUEST['user_id'];  //账号id
		$sign = $_REQUEST['sign'];  //签名
		
		$mysign = $amount.$bill_no.$extra.$game_id.$server_id.$user_id.$paymentKey;
		
		if($sign == strtoupper(md5($mysign)))  
		{ //验证通过
			 
			//进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $amount, $extra, "baofeng", $platform,$bill_no))
			{
				$ret="failure";
				$orderLog->log("baofeng",array("order"=>$extra,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="success";
				$orderLog->log("baofeng",array("order"=>$extra,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$orderLog->log("baofeng","  order:$extra  sign error sign:$sign mysign:$mysign");
			$ret="failure";
		}
		return $ret;
	}
	
}